#!/bin/sh

/bin/echo "Starting sys service ..."


# Exec boot process
cd /usr/local/apache2/htdocs/ && /usr/local/php/bin/php -f /usr/local/bin/boot.php &&  cd /

# Start syslogd
/usr/local/sbin/syslogd -f /usr/local/etc/syslog.conf  1>/dev/null 2>&1

# Start backup log every 60M.
mkdir /var/spool/cron/crontabs -p
echo "*  3 * * * /usr/local/clamav/bin/freshclam" > /var/spool/cron/crontabs/root
echo "*  2 * * * /usr/sbin/client" >> /var/spool/cron/crontabs/root
echo "50 * * * * /usr/sbin/ntpdate -t 15 210.72.145.44 " >> /var/spool/cron/crontabs/root
echo "45 * * * * /usr/sbin/initor" >> /var/spool/cron/crontabs/root
echo "30 * * * * /usr/local/sbin/logrotate /usr/local/etc/logrotate.conf" >> /var/spool/cron/crontabs/root

# Clean env for free space 
# Find empty dirs or files.
#echo "*/10 * * * * /usr/sbin/cenv.sh" >> /var/spool/cron/crontabs/root
echo "*/5  * * * * /usr/sbin/listen_log.sh" >> /var/spool/cron/crontabs/root
#echo "*    * * * * /usr/sbin/menv.sh" >> /var/spool/cron/crontabs/root

/sbin/crond 

# sshd
if [ ! -f /etc/ssh/ssh_host_key -o ! -f /etc/ssh/ssh_host_dsa_key ]
then
    cd /etc/ssh
    /usr/local/bin/ssh-keygen -t rsa1 -q -b 1024 -f ssh_host_key -N ""
    /usr/local/bin/ssh-keygen -q -d -f ssh_host_dsa_key -N ""
fi
/usr/local/sbin/sshd > /dev/null 2>&1

# We can start telnetd.
# /sbin/telnetd
# Start apache2

/usr/local/apache2/bin/httpd &

# Start p3scan
/usr/local/sbin/p3scan -f /usr/local/etc/p3scan.conf

# Start havp
/bin/mkdir /usr/tmp/havp
/bin/chmod 777 /usr
/bin/chmod 777 /usr/run
/bin/chmod 777 /usr/log
/bin/chmod 777 /usr/tmp
/bin/chmod 777 /usr/tmp/havp
/usr/local/sbin/havp -c /usr/local/etc/havp/havp.config 1>/dev/null 2>&1

# Start frox
#/usr/local/sbin/frox -f /usr/local/etc/frox.conf
/bin/mkdir -p  /usr/tmp/frox
/bin/chmod 777 /usr/tmp/frox
/usr/local/sbin/frox 1>/dev/null 2>&1

# Monitor system process 
/usr/local/bin/monit 1>/dev/null 2>&1
/usr/sbin/client 1>/dev/null 2>&1
# Record boot time
/bin/echo -n "BOOT " >> /ldisk/system/boot.log 
/bin/date >> /ldisk/system/boot.log 

# Init report 
/usr/sbin/listen_log.sh
